﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Portal.Web.Model;
using Portal.Web.Utility;
using Portal.Exam.Bussiness;
using Portal.Core;

namespace Portal.Exam.Render
{
    public class ExamRoom
    {
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);

                bool CheckAllowMan = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, ExamPermission.StaticId, ExamPermission.funcRoomManage, ExamPermission.StaticId, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                

                string SelectExamType =
                  "<select id=drpSelectExamType onchange=\"javascript:DetectExamSegment();\">\r\n" +
                  "   <option value=\"exam\">Thi thật</option>\r\n" +
                  "   <option value=\"test\">Thi thử</option>\r\n" +
                  "</select>\r\n";

                string SelectActive =
                    "<select id=drpSelectActive>\r\n" +
                    "   <option value=\"1\">Đang sử dụng</option>\r\n" +
                    "   <option value=\"0\">Đã xong</option>\r\n" +
                    "</select>\r\n";

                string SelectOpenExam =
                    "<select id=drpSelectOpenExam>\r\n" +
                    "   <option value=\"-1\">Toàn bộ</option>\r\n" +
                    "   <option value=\"1\">Đang mở cho thi</option>\r\n" +
                    "   <option value=\"0\">Đang đóng</option>\r\n" +
                    "</select>\r\n";



                StringBuilder RetHtml = new StringBuilder();
                RetHtml.Append(
                #region Javascript
"<script language=javascript> \r\n" +

                    "    function ClientLoadRecord(Id)\r\n" +
                    "    {\r\n" +
                    "        document.getElementById('txtSelectedUserType').value=Id;\r\n" +
                    "        ClientReading();\r\n" +
                    "        DetectExamSegment();\r\n" +
                    "    }\r\n" +

                    "    function ClientReading()\r\n" +
                    "    {\r\n" +
                    "        SiteId='" + SiteId + "';\r\n" +
                    "        UserType = document.getElementById('txtSelectedUserType').value;\r\n" +
                    "        PageIndex = document.getElementById(\"txtPageIndex\").value; \r\n" +
                    "       Keyword = document.getElementById(\"txtKeyword\").value; \r\n" +
                    "        ExamSegmentId=document.getElementById('drpSelectExamSegment').value;\r\n" +
                    "       Active = document.getElementById(\"drpSelectActive\").value; \r\n" +
                    "       OpenExam = document.getElementById(\"drpSelectOpenExam\").value; \r\n" +
                    "       ExamType = document.getElementById(\"drpSelectExamType\").value; \r\n" +
                    "        AjaxOut = Portal.Exam.Render.ExamRoom.ServerSideReadingExamRoom(SiteId, UserType, ExamSegmentId,Active,OpenExam,Keyword,PageIndex,ExamType).value;\r\n" +
                    "        if(AjaxOut.Error)\r\n" +
                    "        {\r\n" +
                    "            alert(AjaxOut.InfoMessage);\r\n" +
                    "            return;\r\n" +
                    "        }\r\n" +
                    "        document.getElementById('divExamRoomMain').innerHTML = AjaxOut.HtmlContent;\r\n" +
                    "    }\r\n" +

                    "   function DetectExamSegment()\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       ExamType = document.getElementById(\"drpSelectExamType\").value; \r\n" +
                    "       AccountType = document.getElementById('txtSelectedUserType').value;\r\n" +
                    "       AjaxOut = Portal.Exam.Render.ExamRoom.ServerSideReadingExamSegment(SiteId,ExamType,AccountType).value; \r\n" +
                    "       document.getElementById('divSegment').innerHTML=AjaxOut.HtmlContent;\r\n" +
                    "       JumPageExamRoom(0);\r\n" +
                    "   }\r\n" +

                    "   function ClientDeleteExamRoom(ExamRoomId) { \r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "    Msg = Portal.Exam.Render.ExamRoom.ServerSideCheckDeleteExamRoom(SiteId).value; \r\n" +
                    "    if (Msg.indexOf(\"ERROR\") != -1) { \r\n" +
                    "        alert(Msg); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +

                    "    Msg = 'Bạn đã chắc chắn xóa chưa?'; \r\n" +
                    "    if (confirm(Msg) == false) return; \r\n" +
                    "    RetValue = Portal.Exam.Render.ExamRoom.ServerSideDeleteExamRoom(SiteId, ExamRoomId).value; \r\n" +
                    "    if (RetValue.indexOf(\"ERROR\") != -1) { \r\n" +
                    "        alert(RetValue); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +
                    "    alert(RetValue); \r\n" +
                    "    RealJumpPageExamRoom(); \r\n" +
                    "} \r\n" +

                    "function JumPageExamRoom(PageIndex) { \r\n" +
                    "   document.getElementById('txtPageIndex').value=PageIndex;\r\n" +
                    "   document.getElementById(\"divProcessing\").innerHTML = 'Đang đọc dữ liệu từ máy chủ...'; \r\n" +
                    "   setTimeout(\"RealJumpPageExamRoom()\", 10); \r\n" +
                    "} \r\n" +

                    "function RealJumpPageExamRoom() { \r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "    UserType = document.getElementById('txtSelectedUserType').value;\r\n" +
                    "    PageIndex = document.getElementById(\"txtPageIndex\").value; \r\n" +
                    "    Keyword = document.getElementById(\"txtKeyword\").value; \r\n" +
                    "    ExamSegmentId=document.getElementById('drpSelectExamSegment').value;\r\n" +
                    "    Active = document.getElementById(\"drpSelectActive\").value; \r\n" +
                    "    OpenExam = document.getElementById(\"drpSelectOpenExam\").value; \r\n" +
                    "    ExamType = document.getElementById(\"drpSelectExamType\").value; \r\n" +
                    "    AjaxOut = Portal.Exam.Render.ExamRoom.ServerSideReadingExamRoom(SiteId,UserType, ExamSegmentId, Active, OpenExam, Keyword, PageIndex,ExamType).value; \r\n" +
                    "    if (AjaxOut.Error) { \r\n" +
                    "        alert(AjaxOut.InfoMessage); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +
                    "    document.getElementById(\"divProcessing\").innerHTML = \"\"; \r\n" +
                    "    document.getElementById(\"divExamRoomMain\").innerHTML = AjaxOut.HtmlContent; \r\n" +
                    "} \r\n" +


                    "    function ClientAddExamRoom()\r\n" +
                    "    {\r\n" +
                    "         SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "         if(SelectedNode==null)\r\n" +
                    "         {\r\n" +
                    "            alert('Chưa xác định vào nhóm cần thêm!');\r\n" +
                    "            return;\r\n" +
                    "         }\r\n" +

                    "        AccountType = SelectedNode.data.href;\r\n" +

                    "        if(AccountType=='root')\r\n" +
                    "        {\r\n" +
                    "            alert('Chưa xác định vào nhóm cần thêm! Không thể thêm vào nhóm gốc!');\r\n" +
                    "            return;\r\n" +
                    "        }\r\n" +
                    "        ExamSegmentId=document.getElementById('drpSelectExamSegment').value;\r\n" +
                    "         AjaxOut = Portal.Exam.Render.ExamRoom.GetAddExamUrl(SiteId,ExamSegmentId,AccountType).value; \r\n" +
                    "        if(AjaxOut.Error)\r\n" +
                    "           {\r\n" +
                    "               alert(AjaxOut.InfoMessage);\r\n" +
                    "               return;\r\n" +
                    "           }\r\n" +
                    "        window.open(AjaxOut.RetUrl, '_self'); \r\n" +
                    "       } \r\n" +


                    "function ClientUpdateExamRoom(ExamRoomId) { \r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "    Url = Portal.Exam.Render.ExamRoom.GetUpdateExamUrl(SiteId,ExamRoomId).value; \r\n" +
                    "    if (Url.indexOf(\"ERROR\") != -1) { \r\n" +
                    "        alert(Url); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +
                    "    window.open(Url, '_self'); \r\n" +
                    "} \r\n" +

                    "function ClientExamStudentList(ExamRoomId) { \r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "    Url = Portal.Exam.Render.ExamRoom.GetUpdateExamStudentUrl(SiteId,ExamRoomId).value; \r\n" +
                    "    if (Url.indexOf(\"ERROR\") != -1) { \r\n" +
                    "        alert(Url); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +
                    "    window.open(Url, '_self'); \r\n" +
                    "} \r\n" +

                    " function ClientStatus(ExamRoomId,Status)\r\n" +
                    " {\r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "    AjaxOut = Portal.Exam.Render.ExamRoom.ServerSideSetStatus(SiteId,ExamRoomId, Status).value; \r\n" +
                    "    if (AjaxOut.Error) { \r\n" +
                    "        alert(AjaxOut.InfoMessage); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +
                    "    document.getElementById('spanButton'+ExamRoomId).innerHTML=AjaxOut.HtmlContent;\r\n" +
                    " }\r\n" +

                    " function ClientOpenRoom(ExamRoomId,Status)\r\n" +
                    " {\r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "    AjaxOut = Portal.Exam.Render.ExamRoom.ServerSideSetOpenRoom(SiteId,ExamRoomId, Status).value; \r\n" +
                    "    if (AjaxOut.Error) { \r\n" +
                    "        alert(AjaxOut.InfoMessage); \r\n" +
                    "        return; \r\n" +
                    "    } \r\n" +
                    "    document.getElementById('spanButtonOpenRoom'+ExamRoomId).innerHTML=AjaxOut.HtmlContent;\r\n" +
                    " }\r\n" +

                    "</script>\r\n" +

                #endregion

 " <input id=\"txtSelectedUserType\" type=\"hidden\">\r\n" +
                    "<input id=txtPageIndex type=hidden value=\"0\">\r\n" +

                    " <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" 
                    //"            <li onclick=\"javascript:ClientImportRoom();\"><img class=image src=\"" + IconRoot + "/Import.png\"><div>Nhập từ tệp</div></li>\r\n" +
                    );
                if (CheckAllowMan)
                {
                    RetHtml.Append(
                    "            <li onclick=\"javascript:ClientAddExamRoom();\"><img class=image src=\"" + IconRoot + "/Add.png\"><div>Thêm mới</div></li>\r\n");
                }
                RetHtml.Append(
                    "            <li onclick=\"javascript:JumPageExamRoom(0);\"><img class=image src=\"" + IconRoot + "/Refresh.png\"><div>Đọc lại</div></li>\r\n" +
                    "            <li onclick=\"javascript:window.open('../../folder.aspx?folder=exam','_self');\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +
                    " <div class=FormFunction id=divListForm>\r\n" +
                        "    <div id=\"divListItems\">\r\n" +
                    "        <table>\r\n" +
                    "        <tr>\r\n" +
                    "            <td class=col1>\r\n" +
                    "                <div class=CssTreeView>\r\n" +
                                        ExamUltility.DrawTreeViewByAccountType(SiteId, WebSessionUtility.GetCurrentLoginUser().UserId).HtmlContent +
                    "                </div>\r\n" +
                    "            </td>\r\n" +
                    "            <td class=col2>\r\n" +
                    "               <div class=\"tabFunction\">Hình thức: " + SelectExamType + " / Kỳ thi: <span id=divSegment>" + ServerSideReadingExamSegment(SiteId, "exam", "").HtmlContent + "</span> / Kiểu: " + SelectActive + " / Trạng thái: " + SelectOpenExam + " / Môn thi: <input id=txtKeyword value=\"\"><input type=button class=button value=\"Lọc\" onclick=JumPageExamRoom(0);></div>\r\n" +
                    "               <div id=divProcessing></div>" +
                    "                <div id=divExamRoomMain>\r\n" +
                                        ServerSideReadingExamRoom(SiteId, "", "", 1, -1, "", 0, "exam").HtmlContent +
                    "                </div>\r\n" +
                    "            </td>\r\n" +
                    "        </tr>\r\n" +
                    "        </table>\r\n" +
                    "    </div>\r\n" +
                    "</div>");
                OAjaxOut.HtmlContent = RetHtml.ToString();
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod]
        public static AjaxOut ServerSideReadingExamRoom(
            string SiteId,
            string UserType,
            string ExamSegmentId,
            int Active,
            int OpenExam,
            string Keyword,
            int CurrentPageIndex,
            string ExamType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                DataTable dtExamRoom = new ExamRoomBll().ReadingExamRoom(SiteId, UserType, ExamSegmentId, Active, OpenExam, Keyword, ExamType);
                ReturnPaging OReturnPaging = WebPaging.GetPaging(dtExamRoom.Rows.Count, CurrentPageIndex, 25, 10, "JumPageExamRoom");

                string RetHtml =
                    "  <h3>Danh sách phòng thi</h3>\r\n" +
                        OReturnPaging.PagingText +
                    "   <div class=\"tabcontent\">\r\n" +
                    "   <table>" +
                    "       <tr>" +
                    "           <th class=thIndex>#</th>" +
                    "           <th>Phòng thi</th>" +
                    "           <th>Môn thi</th>" +
                    "           <th>Toà nhà</th>" +
                    "           <th>Ngày thi</th>" +
                    "           <th>GV1</th>" +
                    "           <th>GV2</th>" +
                    "       </tr>";

                for (int iIndex = OReturnPaging.StartIndex; iIndex < OReturnPaging.EndIndex; iIndex++)
                {
                    string ExamRoomId = (string)dtExamRoom.Rows[iIndex]["ExamRoomId"];
                    bool AllowAccess = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, ExamRoomPermission.StaticId, ExamRoomPermission.funcAccess, ExamRoomId, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                    if (!AllowAccess) continue;

                    bool AllowMan = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, ExamRoomPermission.StaticId, ExamRoomPermission.funcManage, ExamRoomId, WebSessionUtility.GetCurrentLoginUser().UserId, false);                    
                    
                    string RoomNo = (string)dtExamRoom.Rows[iIndex]["RoomNo"];
                    string BuildingInfo = (string)dtExamRoom.Rows[iIndex]["BuildingInfo"];
                    string ExamSubject = (string)dtExamRoom.Rows[iIndex]["ExamSubject"];
                    string Teacher1 = (string)dtExamRoom.Rows[iIndex]["Teacher1"];
                    string Teacher2 = (string)dtExamRoom.Rows[iIndex]["Teacher2"];
                    DateTime StartTime = (DateTime)dtExamRoom.Rows[iIndex]["StartTime"];
                    int ItemActive = (int)dtExamRoom.Rows[iIndex]["ActiveRoom"];
                    int OpenForExam = (int)dtExamRoom.Rows[iIndex]["OpenForExam"];
                    int Duration = (int)dtExamRoom.Rows[iIndex]["Duration"];
                    string Button = "";
                    if (ItemActive == 0)
                    {
                        Button = GetSetActiveButton(SiteId, ExamRoomId);
                    }
                    else
                    {
                        Button = GetSetInActiveButton(SiteId, ExamRoomId);
                    }

                    string ButtonOpenRoom = "";
                    if (OpenForExam == 0)
                    {
                        ButtonOpenRoom = GetActiveOpenRoomButton(SiteId, ExamRoomId);
                    }
                    else
                    {
                        ButtonOpenRoom = GetInActiveOpenRoomButton(SiteId, ExamRoomId);
                    }
                    RetHtml +=
                    "       <tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='normal'\">" +
                    "           <td class=tdIndex>" + (iIndex + 1) + "</td>" +
                    "           <td class=tdCode>" + RoomNo + "</td>" +
                    "           <td>" + ExamSubject + " (" + Duration.ToString("#,##0") + " phút)\r\n" +
                    "               <div>\r\n";
                    if (AllowMan)
                    {
                        RetHtml +=
                    "                   <input type=button class=button value=\"Sửa\" onclick=\"javascript:ClientUpdateExamRoom('" + ExamRoomId + "');\">" +
                    "                   <input type=button class=button value=\"Xóa\" onclick=\"javascript:ClientDeleteExamRoom('" + ExamRoomId + "');\">" +
                    "                   <span id=\"spanButton" + ExamRoomId + "\">" + Button + "</span>\r\n" +
                    "                   <span id=\"spanButtonOpenRoom" + ExamRoomId + "\">" + ButtonOpenRoom + "</span>\r\n";
                    }                    
                    RetHtml +=
                    "                   <input type=button class=button value=\"D.Sách\" onclick=\"javascript:ClientExamStudentList('" + ExamRoomId + "');\">\r\n" +                    
                    "               </div>\r\n" +
                    "           </td>" +
                    "           <td>" + BuildingInfo + "</td>" +
                    "           <td class=tdDate>" + StartTime.ToString("dd/MM/yyyy") + "</td>" +
                    "           <td>" + Teacher1 + "</td>" +
                    "           <td>" + Teacher2 + "</td>" +
                    "       </tr>";
                }
                RetHtml +=
                    "   </table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = RetHtml;

            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod]
        public static AjaxOut ServerSideReadingExamSegment(
            string SiteId,
            string ExamType,
            string AccountType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                DataTable dt = new ExamSegmentBll().ReadingExamSegmentForAccountType(SiteId, ExamType, 1, "", AccountType);
                string SelectExamSegment =
                    "<select id=drpSelectExamSegment>\r\n";
                for (int iIndex = 0; iIndex < dt.Rows.Count; iIndex++)
                {
                    string ExamSegmentId = (string)dt.Rows[iIndex]["ExamSegmentId"];
                    string ExamSegmentName = (string)dt.Rows[iIndex]["ExamSegmentName"];
                    SelectExamSegment += "    <option value=\"" + ExamSegmentId + "\">" + ExamSegmentName + "</option>\r\n";
                }
                SelectExamSegment += "</select>\r\n";
                OAjaxOut.HtmlContent = SelectExamSegment;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod]
        public static string GetSetActiveButton(string SiteId, string ExamRoomId)
        {
            string Html =
                "<input type=button class=button value=\"Cho phép sử dụng\" onclick=\"javascript:ClientStatus('" + ExamRoomId + "',1);\">";
            return Html;
        }

        [AjaxPro.AjaxMethod]
        public static string GetSetInActiveButton(string SiteId, string ExamRoomId)
        {
            string Html =
                "<input type=button class=button value=\"Ngừng sử dụng\" onclick=\"javascript:ClientStatus('" + ExamRoomId + "',0);\">";
            return Html;
        }


        [AjaxPro.AjaxMethod]
        public static string GetActiveOpenRoomButton(string SiteId, string ExamRoomId)
        {
            string Html =
                "<input type=button class=button value=\"Mở phòng thi\" onclick=\"javascript:ClientOpenRoom('" + ExamRoomId + "',1);\">";
            return Html;
        }

        [AjaxPro.AjaxMethod]
        public static string GetInActiveOpenRoomButton(string SiteId, string ExamRoomId)
        {
            string Html =
                "<input type=button class=button value=\"Đóng phòng thi\" onclick=\"javascript:ClientOpenRoom('" + ExamRoomId + "',0);\">";
            return Html;
        }

        [AjaxPro.AjaxMethod]
        public AjaxOut GetAddExamUrl(
            string SiteId,
            string ExamSegmentId,
            string AccountType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                if (string.IsNullOrEmpty(ExamSegmentId)) throw new Exception("Chưa xác định kỳ thi!");
                OAjaxOut.RetUrl = "AddExamRoom.aspx?ExamSegmentId=" + ExamSegmentId + "&AccountType=" + AccountType;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod]
        public string GetConfirmDeleteMsg(string SiteId)
        {
            return "Bạn đã chắc chắn xóa chưa?";
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideCheckDeleteExamRoom(string SiteId, string ExamRoomId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideDeleteExamRoom(string SiteId, string ExamRoomId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                new ExamRoomBll().DeleteExamRoom(null, SiteId, ExamRoomId);
                return "Xóa thành công";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetUpdateExamUrl(string SiteId, string ExamRoomId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                string UpdateUrl = "UpdateExamRoom.aspx?ExamRoomId=" + ExamRoomId;
                return UpdateUrl;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetUpdateExamStudentUrl(string SiteId, string ExamRoomId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                string UpdateUrl = "ExamRoomStudent.aspx?ExamRoomId=" + ExamRoomId;
                return UpdateUrl;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string GetProcessingText()
        {

            return "Đang đọc dữ liệu từ máy chủ";
        }

        [AjaxPro.AjaxMethod]
        public AjaxOut ServerSideSetStatus(
            string SiteId,
            string ExamRoomId,
            int iActive)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                new ExamRoomBll().SetStatus(null, SiteId, ExamRoomId, iActive);
                if (iActive == 1)
                {
                    OAjaxOut.HtmlContent = GetSetInActiveButton(SiteId, ExamRoomId);
                }
                if (iActive == 0)
                {
                    OAjaxOut.HtmlContent = GetSetActiveButton(SiteId, ExamRoomId);
                }
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod]
        public AjaxOut ServerSideSetOpenRoom(
            string SiteId,
            string ExamRoomId,
            int iActive)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                new ExamRoomBll().SetOpenExam(null, SiteId, ExamRoomId, iActive);
                if (iActive == 1)
                {
                    OAjaxOut.HtmlContent = GetInActiveOpenRoomButton(SiteId, ExamRoomId);
                }
                if (iActive == 0)
                {
                    OAjaxOut.HtmlContent = GetActiveOpenRoomButton(SiteId, ExamRoomId);
                }
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

    }
}
